package com.foreveross.proxyip.util;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
 * LatchControl是CountDownLatch的被动式
 * @author lyq
 *
 */
public class LatchControl {
	Long timeout = 1L;
	public LatchControl(Long timeout){
		this.timeout = timeout;
	}
	
	public CountDownLatch latch = null;
	
	public void waitLatch() throws InterruptedException{
		if(latch!=null){
			latch.await(this.timeout*2,TimeUnit.MILLISECONDS);
		}
	}
	
	public void wakeupWait() throws InterruptedException{
		latch = new CountDownLatch(1);
//		Thread.sleep(this.timeout);//缓冲执行
	}
	public void countDown(){
		latch.countDown();
		latch = null;
	}
	
}
